﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Hired.Classes
{
    public class DBDocument
    {
        //add document
        public static bool addDocument(DocumentRoster d)
        {
            try
            {
                using (hireddbEntities db = new hireddbEntities())
                {
                    db.AddToDocumentRosters(d);
                    db.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        //Retrieve a document by ID
        public static DocumentRoster retrieveDocument(string accountID)
        {
            DocumentRoster doc = null;
            using (hireddbEntities db = new hireddbEntities())
            {
                    doc =
                    (from a in db.DocumentRosters
                    where a.AccountID == accountID
                    select a).SingleOrDefault();
            }

            return doc;
        }
        public static List<DocumentRoster> retrieveDocumentsById(string accountID)
        {

            using (hireddbEntities db = new hireddbEntities())
            {
                return (
                 from a in db.DocumentRosters
                 where a.AccountID == accountID
                 select a).ToList<DocumentRoster>();
            }
        }
        //delete doc by id
        public static bool deletDocById(string id)
        {
            try
            {
                DocumentRoster docToDelete = retrieveDocument(id);
                using (hireddbEntities db = new hireddbEntities())
                {
                    db.Attach(docToDelete);
                    db.DeleteObject(docToDelete);
                    db.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}